/// The Trix struct in the YATA library, documented at https://docs.rs/yata/latest/yata/indicators/struct.Trix.html, is an implementation of the Triple Exponential Moving Average (TRIX) indicator, which is a momentum oscillator used in technical analysis to identify trend direction and potential turning points in financial markets.
///
/// Key Features of TRIX:
/// Main Value and Signal Line: TRIX calculates two primary values:
///
/// Main Value: This represents the percentage rate of change of a triple exponentially smoothed moving average of the price. Its range is from negative infinity to positive infinity, reflecting the degree and direction of price momentum.
/// Signal Line: This is typically a moving average of the main TRIX value, often used to generate trading signals. It also ranges from negative infinity to positive infinity.
/// Trading Signals:
///
/// Directional Changes: If the main TRIX value changes direction from down to up, it suggests a buying opportunity (full buy signal). Conversely, if it changes direction from up to down, it suggests a selling opportunity (full sell signal).
/// Crossing Signal Line: When the main TRIX value crosses above the signal line, it generates a full buy signal, and when it crosses below, it generates a full sell signal.
/// Crossing Zero Line: Crossing the zero line is also significant; an upward crossover from negative to positive territory indicates a buy signal, while a downward crossover into negative territory signals a sell.
/// Source Type: By default, TRIX uses the closing price (Close) of a financial instrument for its calculations, but this can be customized.
///
/// Dynamic Initialization and Configuration: The Trix struct is designed to dynamically initialize its state based on the provided configuration, which can include parameters such as the lookback period for calculating the TRIX and the type or period of the signal line moving average.
///
/// Usage: It operates over a series of Open-High-Low-Close (OHLC) data, evaluating the configured IndicatorConfig to produce a series of IndicatorResults. This allows traders to analyze the momentum of the asset and make informed trading decisions based on the generated signals.
///
/// Conclusion:
/// The Trix struct offers traders a tool for analyzing momentum shifts and identifying potential trend reversals in financial markets. By tracking the rate of change in a triple-exponentially smoothed moving average, TRIX provides signals for both directional changes and crossovers, which can be valuable for timing entries and exits in trades. Its dynamic configuration capabilities ensure adaptability to different trading styles and market conditions.
///
///
use serde::{Deserialize, Serialize};
use ts_rs::TS;

use super::IndicatorActionWrap;

/// Assuming TRIX is meant to hold the computed TRIX values and signals.
///
/// 参见[Trix](https://docs.rs/yata/latest/yata/indicators/struct.Trix.html)
/// Struct yata::indicators::Trix
#[derive(Serialize, Deserialize, Debug, TS, Clone)]
#[ts(export)]
pub struct TRIX {
    ///
    ///3 signals
    /// When main value changes direction upwards, returns full buy signal.
    /// When main value changes direction downwards, returns full sell signal.
    /// Otherwise returns no signal.
    pub signal0: Option<IndicatorActionWrap>,
    ///
    /// When main value crosses signal line value upwards, returns full buy signal.
    /// When main value crosses signal line value downwards, returns full sell signal.
    /// Otherwise returns no signal.
    pub signal1: Option<IndicatorActionWrap>,
    ///
    /// When main value crosses zero line upwards, returns full buy signal.
    /// When main value crosses zero line downwards, returns full sell signal.
    /// Otherwise returns no signal.
    pub signal2: Option<IndicatorActionWrap>,

    /// main value
    /// Range is (-inf; +inf)
    pub main: f64,
    ///signal line value
    ///Range is (-inf; +inf)
    pub signal: f64,
}

/// Configuration for Triple Exponential Moving Average (TRIX) indicator
#[derive(Serialize, Deserialize, Debug, TS, Clone, Copy)]
#[ts(export)]
pub struct TRIXConfig {
    /// TRIX period. Default is 18.
    ///
    /// Range in [3; PeriodType::MAX)
    pub period1: u8,

    /// Signal line moving average type.
    ///
    /// Default is EMA(6).
    ///Period range is in [2; PeriodType::MAX)
    pub signal: u8,
    // source: Source
    // Source type. Default is Close
}
impl Default for TRIXConfig {
    fn default() -> Self {
        Self {
            period1: 18,
            signal: 6,
        }
    }
}
